package LC;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
 * @ClassName 面试题34
 * @Description: TODO
 * @Author hl
 * @Date 2021/3/27
 * @Version V1.0
 **/
public class LC13 {
    public static void main(String[] args) {
        System.out.println(romanToInt("LVIII"));
    }
    public static int romanToInt(String s) {
    HashMap<Character,Integer> map=new HashMap<>();
    map.put('I',1);
    map.put('V',5);
    map.put('X',10);
    map.put('L',50);
    map.put('C',100);
    map.put('D',500);
    map.put('M',1000);
    int sum=0;
    for(int i=0;i<s.length();i++){
        if(i+1<s.length()&&map.get(s.charAt(i))<map.get(s.charAt(i+1))){
            sum=sum-map.get(s.charAt(i));
        }else{
            sum+=map.get(s.charAt(i));
        }
    }
    return sum;

    }
}
